# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-lemon
pkgver=0.9.1
# https://github.com/rubyworks/lemon/issues/16
_commit=182f6cb0202fcd267ef296fcc19d46efa68ab091
pkgrel=1
pkgdesc='Pucker-Strength Unit Testing'
arch=(any)
url='https://github.com/rubyworks/lemon'
license=(BSD)
depends=(ruby-rubytest-cli ruby-ae ruby-ansi)
checkdepends=(ruby-qed)
options=(!emptydirs)
source=(https://github.com/rubyworks/lemon/archive/$_commit/$pkgname-$_commit.tar.gz)
sha256sums=('7b5ca2e61a6000cf4b96e03bcf1b12dac453568adfb2e3606378711b680c8242')

prepare() {
  cd lemon-$_commit
  sed -i -e 's/rubytest/rubytest-cli/' -e 's/Test::Runner.cli(\*ARGV)/Test::CLI.run(ARGV)/' lib/lemon/cli.rb
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd lemon-$_commit
  gem build pkg/lemon.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    lemon-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd lemon-$_commit
  PATH="$PWD/tmp_install/usr/bin:$PATH" GEM_HOME="tmp_install/$_gemdir" lemons test -Ilib -Itest/fixtures test/*.rb
  PATH="$PWD/tmp_install/usr/bin:$PATH" GEM_HOME="tmp_install/$_gemdir" qed
}

package() {
  cd lemon-$_commit
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
